package com.cxzl.pcxt.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.cxzl.pcxt.dao.PaperDao;
import com.cxzl.pcxt.entity.Paper;

@Service("pcxtPaperService")
@Transactional
public class PaperService {

	@Resource(name = "pcxtPaperDao")
	private PaperDao paperDao;

	public List<Paper> findByList() {
		return paperDao.findListBySearch( 0, 10);
	}

	/**
	 * 创建考试
	 * 
	 * @param entity
	 */
	public void createPaper(Paper entity) {
		Assert.notNull(entity, "试卷不能为空");
		Assert.hasText(entity.getTitle(), "标题不能为空");
		entity.setState(Paper.STATE_CREATE);
		entity.setCreateTime(new Date());
		paperDao.saveEntity(entity);
	}

	/**
	 * 根据ID查询试卷
	 * 
	 * @param i
	 * @return
	 */
	public Paper findById(int id) {
		return paperDao.findById(id);
	}

	/**
	 * 修改考试状态
	 * 
	 * @param sTATE_ING
	 * @param papreId
	 */
	public void updateState(int state, Integer id) {
		paperDao.updateState(state, id);
	}
}
